package com.wanbatv.wangwangba.util;

import android.content.Context;
import android.os.Build;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.wanbatv.wangwangba.utils.Product;

import java.util.HashMap;
import java.util.Map;


/**
 * Created by 俞亚楠 on 2015/8/5.
 */
public class Behavior {
    //用户id
    public static String USERID=null;
    //机顶盒设备id
    public static String STBID=null;
    //机顶盒序列号
    public static String STBSN=null;
    //机顶盒品牌名称
    public static String STBNAME=null;
    //平台标识
    public static int PLATFORM=3;
    //事件发生时间时间戳
    public static long TIME=0;
    //渠道名称
    public static String FLAVOR=null;
    //行为代码
    public static int ACTIONCODE=0;
    //应用唯一编码
    public static String APPKEY="b92dc4179fde7921254dedd22ad38fce";

    /**
     * 用户id
     * @return
     */
    public static String userid(){
        USERID=Build.SERIAL;
        return USERID;
    }
    /**
     * 机顶盒设备id
     * @return
     */
    public static String stbid(){
        STBID=Build.SERIAL;
        return STBID;
    }
    /**
     * 机顶盒序列号
     * @return
     */
    public static String stbsn(){
        STBSN=Build.SERIAL;
        return STBSN;
    }
    /**
     * 机顶盒品牌名称
     * @return
     */
    public static String stbname(){
        STBNAME=Build.MANUFACTURER+"_"+Build.MODEL;
       return STBNAME;

    }
    /**
     * 平台标识
     */
    public static int platform(){
        return PLATFORM;
    }
    /**
     * 渠道名称
     */
    public static String flavor(){
        FLAVOR=Product.flavor;
        return FLAVOR;
    }
    /**
     * 事件发生时间时间戳
     * @return
     */
    public static long time(){
        TIME=System.currentTimeMillis();
        return TIME;
    }
    /**
     * 行为代码
     */
    public static int actioncode(){
        return ACTIONCODE;
    }
    /**
     * 应用唯一编码
     */
    public static String appkey(){
        return APPKEY;
    }

    public static void onPageResume(Context context, final int pageCode, final String pageName) {
        RequestQueue requestQueue = Volley.newRequestQueue(context);
        String url = "http://121.201.7.173:8086/cake/reportaction/page";
        StringRequest stringRequest = new StringRequest(com.android.volley.Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //在这里设置需要post的参数
                Map<String, String> map = new HashMap<String, String>();
                map.put("userid", Behavior.userid());
                map.put("stbid", Behavior.stbid());
                map.put("stbsn",Behavior.stbsn());
                map.put("stbname",Behavior.stbname());
                map.put("platform",Behavior.platform()+"");
                map.put("time",Behavior.time()+"");
                map.put("flavor",Behavior.flavor());
                map.put("actioncode","1000001");
                map.put("appkey",Behavior.appkey());
                map.put("pagecode",pageCode+"");
                map.put("pagename",pageName);
                return map;
            }
        };
        requestQueue.add(stringRequest);
    }

    public static void onPagePause(Context context, final int pageCode, final String pageName) {
        RequestQueue requestQueue = Volley.newRequestQueue(context);
        String url = "http://121.201.7.173:8086/cake/reportaction/page";
        StringRequest stringRequest = new StringRequest(com.android.volley.Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //在这里设置需要post的参数
                Map<String, String> map = new HashMap<String, String>();
                map.put("userid", Behavior.userid());
                map.put("stbid", Behavior.stbid());
                map.put("stbsn",Behavior.stbsn());
                map.put("stbname",Behavior.stbname());
                map.put("platform",Behavior.platform()+"");
                map.put("time",Behavior.time()+"");
                map.put("flavor",Behavior.flavor());
                map.put("actioncode","1000002");
                map.put("appkey",Behavior.appkey());
                map.put("pagecode",pageCode+"");
                map.put("pagename",pageName);
                return map;
            }
        };
        requestQueue.add(stringRequest);

    }

    public static void onAppStart(Context context) {
        RequestQueue requestQueue = Volley.newRequestQueue(context);
        String url = "http://121.201.7.173:8086/cake/reportaction/page";
        StringRequest stringRequest = new StringRequest(com.android.volley.Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //在这里设置需要post的参数
                Map<String, String> map = new HashMap<String, String>();
                map.put("userid", Behavior.userid());
                map.put("stbid", Behavior.stbid());
                map.put("stbsn",Behavior.stbsn());
                map.put("stbname",Behavior.stbname());
                map.put("platform",Behavior.platform()+"");
                map.put("time",Behavior.time()+"");
                map.put("flavor",Behavior.flavor());
                map.put("actioncode","1000003" );
                map.put("appkey",Behavior.appkey());
                map.put("pagecode","0");
                map.put("pagename","进入应用");
                return map;
            }
        };
        requestQueue.add(stringRequest);
    }

    public static void onAppEnd(Context context) {
        RequestQueue requestQueue = Volley.newRequestQueue(context);
        String url = "http://121.201.7.173:8086/cake/reportaction/page";
        StringRequest stringRequest = new StringRequest(com.android.volley.Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //在这里设置需要post的参数
                Map<String, String> map = new HashMap<String, String>();
                map.put("userid", Behavior.userid());
                map.put("stbid", Behavior.stbid());
                map.put("stbsn",Behavior.stbsn());
                map.put("stbname",Behavior.stbname());
                map.put("platform",Behavior.platform()+"");
                map.put("time",Behavior.time()+"");
                map.put("flavor",Behavior.flavor());
                map.put("actioncode","1000004" );
                map.put("appkey",Behavior.appkey());
                map.put("pagecode","0");
                map.put("pagename","退出应用");
                return map;
            }
        };
        requestQueue.add(stringRequest);
    }

    public static void onPlayContentStart(Context context,final int catecode,final String catename,final int contentcode,final String contentname) {
        RequestQueue requestQueue = Volley.newRequestQueue(context);
        String url = "http://121.201.7.173:8086/cake/reportaction/content";
        StringRequest stringRequest = new StringRequest(com.android.volley.Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //在这里设置需要post的参数
                Map<String, String> map = new HashMap<String, String>();
                map.put("userid", Behavior.userid());
                map.put("stbid", Behavior.stbid());
                map.put("stbsn",Behavior.stbsn());
                map.put("stbname",Behavior.stbname());
                map.put("platform",Behavior.platform()+"");
                map.put("time",Behavior.time()+"");
                map.put("flavor",Behavior.flavor());
                map.put("actioncode","2000001" );
                map.put("appkey",Behavior.appkey());
                map.put("catecode",catecode+"");
                map.put("catename",catename);
                map.put("contentcode",contentcode+"");
                map.put("contentname",contentname);
                return map;
            }
        };
        requestQueue.add(stringRequest);
    }

    public static void onPlayContentStop(Context context,final int catecode,final String catename,final int contentcode,final String contentname) {
        RequestQueue requestQueue = Volley.newRequestQueue(context);
        String url = "http://121.201.7.173:8086/cake/reportaction/content";
        StringRequest stringRequest = new StringRequest(com.android.volley.Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //在这里设置需要post的参数
                Map<String, String> map = new HashMap<String, String>();
                map.put("userid", Behavior.userid());
                map.put("stbid", Behavior.stbid());
                map.put("stbsn",Behavior.stbsn());
                map.put("stbname",Behavior.stbname());
                map.put("platform",Behavior.platform()+"");
                map.put("time",Behavior.time()+"");
                map.put("flavor",Behavior.flavor());
                map.put("actioncode","2000002" );
                map.put("appkey",Behavior.appkey());
                map.put("catecode",catecode+"");
                map.put("catename",catename);
                map.put("contentcode",contentcode+"");
                map.put("contentname",contentname);
                return map;
            }
        };
        requestQueue.add(stringRequest);
    }

    public static void onEvent(Context context, final int eventCode, final String eventName) {
        RequestQueue requestQueue = Volley.newRequestQueue(context);
        String url = "http://121.201.7.173:8086/cake/reportaction/event";

        StringRequest stringRequest = new StringRequest(com.android.volley.Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //在这里设置需要post的参数
                Map<String, String> map = new HashMap<String, String>();
                map.put("userid", Behavior.userid());
                map.put("stbid", Behavior.stbid());
                map.put("stbsn",Behavior.stbsn());
                map.put("stbname",Behavior.stbname());
                map.put("platform",Behavior.platform()+"");
                map.put("time",Behavior.time()+"");
                map.put("flavor",Behavior.flavor());
                map.put("actioncode","" + eventCode);
                map.put("appkey",Behavior.appkey());
                map.put("eventname",eventName);
                return map;
            }
        };
        requestQueue.add(stringRequest);
    }
}


